var form,$,table;
layui.use(['form','jquery','table'],function() {
    form = layui.form;
    $ = layui.jquery;
    table = layui.table;

    //获取微圈操作日志表数据
    getLogData('', '', '', '');
});

function getLogData(trueName, remark, type, createDate) {
    $.ajax({
        url: "/microcircle/getLog",
        type: "post",
        dataType: "json",
        data: {
            'trueName': trueName ,
            'remark': remark,
            'type': type,
            'createDate': createDate,
        },
        success: function (item) {
            //展示table表格
            getLogTable(item.data);
        }
    });
}

function getLogTable(data) {
    table.render({
        elem: '#demo' ,
        data: data,
        toolbar:'#toolutil',
        page: true,
        limit: 10,
        cols:[[
            {type:'checkbox',},
            {title:'序号', align:'center' ,width:70, templet:function (data) {
                    return data.logId;
                }},
            {field:'trueName',title:'管理员名称',align:'center'},
            {field:'remark',title:'操作列表',align:'center'},
            {field:'createDate',title:'执行时间',align:'center'},
            {field:'type',title:'操作类型',align:'center',templet: function (data) {
                    var type;
                    if (data.type == 2){
                        type = "添加";
                    }
                    if (data.type == 3){
                        type = "删除";
                    }
                    if (data.type == 4){
                        type = "修改";
                    }
                    if (data.type == 5){
                        type = "查看";
                    }
                    return type;
                }},
            {field:'',title:'备注',align:'center',templet:function () {
                    return "无内容";
                }},
            {field:'',title:'操作',align:'center',templet:function(data){
                    return "<a class='operation' href='javascript:del(\"" + data.logId + "\");'>删除</a>"
                }},
        ]]
    });
}

//删除操作日志
function del(logId) {
    layer.open({
        type: 1,
        title: "删除操作日志",
        content: "<div style='font-size: 16px; margin: 30px;'>您确定要删除此操作日志吗？</div>",
        area: ['300px','200px'],
        btn: ['确定','取消'],
        yes: function (index,layero) {
            $.ajax({
                url: "/microcircle/delLog",
                type: "post",
                dataType: "json",
                data: {"logId": logId},
                success: function (item) {
                    if (item.data){
                        getLogData('', '', '', '');
                        layer.msg("删除成功");
                        layer.close(index);
                    }else {
                        layer.msg("删除失败");
                        layer.close(index);
                    }
                }
            });
        }
    });
}

//搜索
function search() {
    var formData = form.val("formTest");
    getLogData(formData.trueName, formData.remark, formData.type, formData.createDate);
}

//刷新
function load() {
    location.reload();
}

//返回首页
function backOff(){
    parent.jumpSystemHome();
}